WordPress自带的条件标签使用说明
?>
endif;
if(10 == 11):
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
<?php
echo ‘Welcome, registered user!’;
endif;
<?php if ( is_singular( ‘books’ ) ):
用php的条件语句你可以判断一些事情的真假,如果是真,代码将被执行,否则什么也不发生.看下面的语句,相信你可以理解.
if( is_home() AND is_page( 5 ) ):echo ‘<style type=”text/css”>#editor-toolbar #edButtonHTML, #quicktags {display: none;}</style>’;
function single_result() {
条件标签非常有用,它可以用来判断用户是否登陆?用户是否使用是ie浏览器?是否有文章显示等等.
elseif(10 == 15):endif;
# The user is reading a post or a page
endif;
if (is_search()) {
add_action(‘wp_footer’, ‘ga’);
# The user is on a page, but not the homepage
当查询结果仅有一篇时直接以单页的方式显示(这个很好,我觉得)
判断当前的用户可以做什么…
if( stristr($_SERVER['HTTP_USER_AGENT'],”mac”) ):else:
下面的例子可以让你判断当前的文章是否是特定的文章类型,比如books
自定义文章的类型
你同样可以用elseif来增加另一个条件语句,如下:
endif;endif;
_gaq.push(['_trackPageview']);
}
// This post is of the custom post type books.
echo ‘And I’m a PC.’;
?>
?>
用户登陆时,让Google分析代码不起作用
echo ‘Registrations are open.’;// function for inserting Google Analytics into the wp_head
}
else:
… search field …
在WordPress的条件标签一览表里面,你可以看到大部分的content或page的条件标签,如果你继续深究的话,你还会发现以下的.
echo ‘User is on the homepage or the page where the ID is 5′;if ( !is_user_logged_in() ): // íf user is not logged in
if( is_admin() ):
})();
if( is_home() OR is_page( 5 )):
add_filter( ‘wp_default_editor’, create_function(”, ‘return “tinymce”;’) );
}
endif;
检查是否有文章显示,如果没有,则显示搜索框.
如果在你的网站使用了Google的分析代码,你可能希望去跟踪真正的访问者,而不是作者.不要忘记修改Google的分析id的UA-XXXXXXX-X (如下)
endif;add_action(‘template_redirect’, ‘single_result’);
function disable_html_editor_wps() {
<?php
</script>
echo ‘This is false, and will not be shown.’;
添加以下代码片断到你的主题文件夹的functions.php文件里,它将会自动重定向到当你的搜索结果仅有一篇时以单页方式显示.
add_action( ‘admin_head’, ‘disable_html_editor_wps’ );什么时候使用条件标签
<?php你可以查询更多关于WordPress的codex条件标签列表.
有时你查询的条件语句不止一个,你可以使用”和”或”或”即”and”与”or”.
if( is_single() OR is_page() ):… posts …
global $wp_query;
条件标签怎么起作用
echo ‘User is not on the homepage’;
除了admin,使别人禁用Tinymce HTML编辑器
if( current_user_can(‘editor’) ):// true if user is an editor
if ($wp_query->post_count == 1) {
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']); // insert your Google Analytics id here
if ($current_user->user_level != 10) {
# User is administator
<?php if ( get_option(‘users_can_register’):
var _gaq = _gaq || [];
<?php else : ?>
endif;
<?php if ( have_posts() ) : ?>
get_currentuserinfo();
<?php endif; ?>
<script type=”text/javascript”>
以上就是php的条件语句,好了,下面我们进入WordPress的条件标签.
function ga() {endif;
endif;
if( current_user_can(‘edit_posts’) ):
<?php
echo ‘Since none of the above is true, this will be shown.’;
if(10 == 10):
endif; ?>
}
if( is_home() AND is_page(’1′) ):
?>
endif;
echo ‘User is on the homepage.’;
?>
你可能会在你的文章列表里面添加些东西(比如广告或推荐),把以下代码添加到循环内,可以让你在最后一篇文章之前显示出添加的东西。
endif;// true if user can edit posts
你可以把所遇到过的条件标签都整合起来,这些条件标签当你制件主题的时候会很方便,你是否有不同的条件标签,可以拿出来与大家一起分享.
?>echo ‘This is false, and will not be shown.’;
如果你的博客有很多个作者,下面这个代码可以让你知道用户是否登陆.
<?php使用WordPress自带的函数如is_home(),你可以轻松的询问WordPress当前的用户是否在首页.WordPress将会回答你是或否,即1或0.
echo ‘Registrations are closed.’;else:
?>
else:
<?php
echo ‘User is on the homepage, and the home pages ID is 5′;
你的网站是否可以注册
?>ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘’) + ‘.google-analytics.com/ga.js’;
# The user is at the home page and the home page is a page with the ID 1
<?php
WordPress条件标签的用法举例:
<?phpendif;
if( !is_home() AND is_page() ):
检查用户是否登陆
<?php if( ($wp_query->current_post + 1) < ($wp_query->post_count) ): ?>?>
多个条件的混合使用
}}
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
_gaq.push(['_trackPageLoadTime']);
<?php
global $current_user;
endif;
<div class=”separator”></div>
<?php endif; ?>
if( !current_user_can(‘administrator’) ):
if(10 == 15):
echo ‘This is true, and will be shown.’;
// true if user is not admin
检查是否是最后一篇文章
echo ‘This is false, and will not be shown.’;echo ‘Hello, I’m a Mac.’;
echo ‘Welcome, visitor!’;
if( is_home() ):
endif;
自定义条件标签
if ( is_user_logged_in() ):wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
把下面的代码添加到functions.php文件里限制只有admin可以使用编辑器
判断用户使用的电脑是pc或mac(function() {
else:
看下面的例子:
相关热词: 标签
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jz/wp/4869.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
ludou_se_only); } add_action(s
时间:2021-01-23
-
所以经常导致输错密码的
时间:2021-01-23
-
WordPress措施打开速度慢的
时间:2021-01-22
-
WordPress回覆评论自动添加
时间:2021-01-22
-
我们可以通过下面的代码
时间:2021-01-22
-
如何修改WordPress默认脚色
时间:2021-01-20
-
同样的修改文件就行
时间:2021-01-20
-
少数善意的转载者既使没
时间:2021-01-20
热门文章
-
WordPress新手安装教程(图文)
时间:2020-12-28
-
在设置菜单中增加WordPress私密 隐藏的全部
时间:2021-01-10
-
WordPress博客程序常见错误的解决方法
时间:2020-12-28
-
WordPress程序打开速度慢的三种解决方法
时间:2021-01-10
-
wordpress使用代码在每篇文章尾部添加版权
时间:2020-12-14
-
WordPress博客措施常见错误的办理要领
时间:2021-01-15
-
关于WordPress的SEO优化相关的一些PHP页面脚
时间:2021-01-07
-
WordPress措施打开速度慢的三种办理要领
时间:2021-01-22
-
详解WordPress中的头像缓存和署理中的缓存
时间:2021-01-15
-
少数善意的转载者既使没有看到版权信息
时间:2021-01-20
